var a = getApp();

Page({
    data: {
        addlist: [],
        page: 1,
        limit: 100,
        hasMore: !0,
        userId: wx.getStorageSync("userId")
    },
    onLoad: function() {},
    radioChange: function(t) {
        for (var e = this, d = e.data.addlist, s = a.globalData.urlBase + a.globalData.urlUpdateAddress, r = {}, o = 0; o < d.length; o++) d[o].id == t.detail.value ? (d[o].isDefault = 1, 
        d[o].checked = "true", r = d[o]) : (d[o].isDefault = 0, d[o].checked = "");
        e.updateData(s, r, d);
    },
    getinitData: function(a) {
        var t = this;
        t.data.hasMore && wx.request({
            url: a,
            data: {
                page: t.data.page,
                limit: t.data.limit,
                userId: t.data.userId
            },
            method: "POST",
            header: {
                "content-type": "application/x-www-form-urlencoded"
            },
            success: function(a) {
                var e = JSON.parse(a.data);
                if (0 != e.code) wx.showToast({
                    title: e.msg,
                    icon: "none",
                    duration: 2e3
                }); else {
                    for (var d = 0; d < e.orderList.length; d++) 1 == e.orderList[d].isDefault ? e.orderList[d].checked = "true" : e.orderList[d].checked = "";
                    t.setData({
                        addlist: e.orderList
                    });
                }
            }
        });
    },
    updateData: function(a, t, e) {
        var d = this;
        wx.request({
            url: a,
            data: t,
            method: "POST",
            header: {
                "content-type": "application/x-www-form-urlencoded"
            },
            success: function(a) {
                var t = JSON.parse(a.data);
                0 != t.code ? wx.showToast({
                    title: t.msg,
                    icon: "none",
                    duration: 2e3
                }) : d.setData({
                    addlist: e
                });
            }
        });
    },
    delData: function(a, t, e) {
        var d = this;
        wx.request({
            url: a,
            data: t,
            method: "POST",
            header: {
                "content-type": "application/x-www-form-urlencoded"
            },
            success: function(a) {
                var t = JSON.parse(a.data);
                0 != t.code ? wx.showToast({
                    title: t.msg,
                    icon: "none",
                    duration: 2e3
                }) : d.setData({
                    addlist: e
                });
            }
        });
    },
    edit: function(a) {
        var t = a.currentTarget.dataset.id;
        wx.navigateTo({
            url: "../newAddress/newAddress?id=" + t
        });
    },
    del: function(t) {
        for (var e = this, d = t.currentTarget.dataset.id, s = e.data.addlist, r = a.globalData.urlBase + a.globalData.urlDelAddress, o = [], n = 0; n < s.length; n++) s[n].id != d && o.push(s[n]);
        e.delData(r, {
            addressId: d
        }, o);
    },
    onReachBottom: function() {},
    onShow: function() {
        var t = a.globalData.urlBase + a.globalData.urlAddressList;
        this.getinitData(t), console.log("刷新页面了");
    },
    chooseAddress: function(t) {
        var e = t.currentTarget.dataset.id;
        a.globalData.addressId = e, wx.navigateBack({
            url: "../purchase/purchase?id=" + a.globalData.goodsId
        });
    },
    newAddress: function() {
        wx.navigateTo({
            url: "../newAddress/newAddress"
        });
    },
    onShareAppMessage: function() {}
});